Sub ExporterPDF()
    Dim docSource As Document
    Dim docTemp As Document
    Dim i As Long
    Dim nbSections As Long
    Dim chemin As String
    Dim texteSection As String
    Dim refPDF As String
    Dim annee As String
    Dim nomFichier As String
    Dim rngSection As Range
    Dim rngCopie As Range

    Set docSource = ActiveDocument
    chemin = docSource.Path & "\\PDF\\"

    If Dir(chemin, vbDirectory) = "" Then
        MkDir chemin
    End If

    annee = Year(Date)
    nbSections = docSource.Sections.Count

    For i = 1 To nbSections
        Set rngSection = docSource.Sections(i).Range
        texteSection = rngSection.Text

        refPDF = ExtraireValeur(texteSection, "N° REFERENCE:")

        If refPDF = "SANS_REF" Then
            GoTo NextSection
        End If

        nomFichier = chemin & annee & refPDF & ".pdf"

        ' Dupliquer la plage et exclure le saut de section final
        Set rngCopie = rngSection.Duplicate
        rngCopie.MoveEnd wdCharacter, -1

        Set docTemp = Documents.Add

        If rngCopie.Characters.Count > 0 Then
            rngCopie.Copy
            docTemp.Range.Paste
        End If

        docTemp.ExportAsFixedFormat _
            OutputFileName:=nomFichier, _
            ExportFormat:=wdExportFormatPDF

        docTemp.Close SaveChanges:=False

NextSection:
    Next i

    MsgBox "Export terminé !", vbInformation
End Sub

Function ExtraireValeur(texte As String, prefixe As String) As String
    Dim debut As Long
    Dim finLigne As Long

    debut = InStr(texte, prefixe)

    If debut > 0 Then
        debut = debut + Len(prefixe)
        finLigne = InStr(debut, texte, Chr(13))
        If finLigne = 0 Then finLigne = Len(texte)
        ExtraireValeur = Trim(Mid(texte, debut, finLigne - debut))
    Else
        ExtraireValeur = "SANS_REF"
    End If
End Function